package thread.practice;/**
 * Description
 * <p>
 * </p>
 * DATE 2019/12/24.
 *
 * @author cuihao.
 */

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: ch-general
 * @description: 一个线程OOM后其他线程会受到影响吗？
 * @author: cuihao
 * @create: 2019-12-24 11:27
 **/
public class JvmThread {
    static Thread threadA = new Thread(() -> {
        int i = 1;
        try {
            List<byte[]> list = new ArrayList<>();// 不占容量，指向数组
            while (true) {
                System.out.println(new Date() + " === " + Thread.currentThread() + " === " + i);
                byte[] b = new byte[1024 * 1024]; // 1m
                list.add(b);
                Thread.sleep(500);
                ++i;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

    static Thread threadB = new Thread(() -> {
        int i = 1;
        try {
            List<byte[]> list = new ArrayList<>();// 不占容量，指向数组
            while (true) {
                System.out.println(new Date() + " === " + Thread.currentThread() + " === " + i);
                byte[] a = new byte[1024]; // 1m
                list.add(a);
                Thread.sleep(500);
                ++i;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    });

    public static void main(String[] args) {
        try {
            Thread.sleep(10000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        threadA.start();
        threadB.start();
    }

}


/*
 * OOM又分为几类：java.lang.OutOfMemoryError java heap space, PermGen space, Unable to create new native thread
 *
 *
 *
 *
 *
 * */